package cn.doitedu.day01.demo

import org.apache.log4j.{Level, Logger}
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Date 22.3.28
 * @Created by HANGGE
 * @Description
 */
object WordCount02 {
   //设置控制台打印日志的日志级别
  Logger.getLogger("org").setLevel(Level.ERROR)
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setAppName("wordcount")
      .setMaster("local")
    val sc = new SparkContext(conf)
    // 直接加载HDFS上的数据  处理
    val res: RDD[(String, Int)] = sc.textFile("hdfs://linux01:8020/data/wc/")
      .flatMap(_.split("\\s+"))
      .map((_, 1))
      .reduceByKey(_ + _)
      .sortBy(-_._2)
    res.foreach(println)
  }
}
